
#include "stdafx.h"

TEST(ioctlsocketTest, ioctlsocket_in_inout)
{
    SOCKET sock = INVALID_SOCKET;
    u_long argp = 1;
    
    Header header(GetCurrentThreadId(), "ioctlsocket");
    ioctlsocket_in_inout ioctlsocketIN(sock, FIONBIO, &argp);
    ioctlsocket_in_inout ioctlsocketOUT;

    std::vector<char> buffer;
    Serialize(header, ioctlsocketIN, buffer);
        
    Deserialize deserialize(buffer);
    deserialize(ioctlsocketOUT);

    EXPECT_EQ (header.TID_, deserialize.get_header().TID_);
    EXPECT_EQ (header.func_name_, deserialize.get_header().func_name_);

    EXPECT_EQ (ioctlsocketIN.s_, ioctlsocketOUT.s_);
    EXPECT_EQ (ioctlsocketIN.cmd_, ioctlsocketOUT.cmd_);
    if (ioctlsocketIN.argp_ && ioctlsocketOUT.argp_)
    {
        EXPECT_EQ (*ioctlsocketIN.argp_, *ioctlsocketOUT.argp_);
    }
}

TEST(ioctlsocketTest, ioctlsocket_in_inout_NULL_parameters)
{
    SOCKET sock = INVALID_SOCKET;
    
    Header header(GetCurrentThreadId(), "ioctlsocket");
    ioctlsocket_in_inout ioctlsocketIN(sock, FIONBIO, NULL);
    ioctlsocket_in_inout ioctlsocketOUT;

    std::vector<char> buffer;
    Serialize(header, ioctlsocketIN, buffer);
        
    Deserialize deserialize(buffer);
    deserialize(ioctlsocketOUT);

    EXPECT_EQ (header.TID_, deserialize.get_header().TID_);
    EXPECT_EQ (header.func_name_, deserialize.get_header().func_name_);

    EXPECT_EQ (ioctlsocketIN.s_, ioctlsocketOUT.s_);
    EXPECT_EQ (ioctlsocketIN.cmd_, ioctlsocketOUT.cmd_);
    if (ioctlsocketIN.argp_ && ioctlsocketOUT.argp_)
    {
        EXPECT_EQ (*ioctlsocketIN.argp_, *ioctlsocketOUT.argp_);
    }
}

TEST(ioctlsocketTest, ioctlsocket_out_inout)
{
    SOCKET sock = INVALID_SOCKET;
    u_long argp = 1;

    Header header(GetCurrentThreadId(), "ioctlsocket");
    ioctlsocket_out_inout ioctlsocketIN(&argp, 7);
    ioctlsocket_out_inout ioctlsocketOUT;

    std::vector<char> buffer;
    Serialize(header, ioctlsocketIN, buffer);
        
    Deserialize deserialize(buffer);
    deserialize(ioctlsocketOUT);

    EXPECT_EQ (header.TID_, deserialize.get_header().TID_);
    EXPECT_EQ (header.func_name_, deserialize.get_header().func_name_);

    if (ioctlsocketIN.argp_ && ioctlsocketOUT.argp_)
    {
        EXPECT_EQ (*ioctlsocketIN.argp_, *ioctlsocketOUT.argp_);
    }
    EXPECT_EQ (ioctlsocketIN.wsa_last_error_, ioctlsocketOUT.wsa_last_error_);
}

TEST(ioctlsocketTest, ioctlsocket_out_inout_NULL_parameters)
{
    SOCKET sock = INVALID_SOCKET;
    u_long argp = 1;

    Header header(GetCurrentThreadId(), "ioctlsocket");
    ioctlsocket_out_inout ioctlsocketIN(NULL, 7);
    ioctlsocket_out_inout ioctlsocketOUT;

    std::vector<char> buffer;
    Serialize(header, ioctlsocketIN, buffer);
        
    Deserialize deserialize(buffer);
    deserialize(ioctlsocketOUT);

    EXPECT_EQ (header.TID_, deserialize.get_header().TID_);
    EXPECT_EQ (header.func_name_, deserialize.get_header().func_name_);

    if (ioctlsocketIN.argp_ && ioctlsocketOUT.argp_)
    {
        EXPECT_EQ (*ioctlsocketIN.argp_, *ioctlsocketOUT.argp_);
    }
    EXPECT_EQ (ioctlsocketIN.wsa_last_error_, ioctlsocketOUT.wsa_last_error_);
}